#region COPYRIGHT
//--------------------------------------------------------------------------------
// <copyright file="Exponent.cs" company="starLiGHT Entertainment Studios">
//    Copyright (c) 2007, 2008, 2009, 2010, 2011
//       Roland Rosenkranz (Glatzemann@email.de)
//
//    Based on libnoise by Jason Bevins
//      Copyright (C) 2003, 2004 Jason Bevins (licensed under LGPL)
// </copyright>
// <license>
//   This file is part of starLiGHT.Noise.
//
//   starLiGHT.Noise is free software: you can redistribute it and/or modify
//   it under the terms of the GNU Lesser General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//
//   starLiGHT.Noise is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU Lesser General Public License for more details.
//
//   You should have received a copy of the GNU Lesser General Public License
//   along with starLiGHT.Noise. If not, see http://www.gnu.org/licenses/.
//    
//   ADDITIONAL (commercial) LICENSES for starLiGHT.Noise are available on request.
// </license>
// <version>
// **************[ starLiGHT.Engine SVN ]**********************
// * $Rev:: 10385                 $:  Revision of last commit *
// * $Author:: unknown            $:  Author of last commit   *
// * $Date:: 2011-06-14 07:59:17 #$:  Date of last commit     *
// ************************************************************
// </version>
//--------------------------------------------------------------------------------
#endregion

namespace starLiGHT.Noise.Noise
{
    #region Using Statements
    using System;
    using System.Collections.Generic;
    using System.Text;

    #endregion

    /// Noise module that maps the output value from a source module onto an
    /// exponential curve.
    ///
    /// @image html moduleexponent.png
    ///
    /// Because most noise modules will output values that range from -1.0 to
    /// +1.0, this noise module first normalizes this output value (the range
    /// becomes 0.0 to 1.0), maps that value onto an exponential curve, then
    /// rescales that value back to the original range.
    ///
    /// This noise module requires one source module.
    public class Exponent : Module
    {
        /// Exponent to apply to the output value from the source module.
        protected double exponent;

        /// Default exponent for the noise::module::Exponent noise module.
        private const double DEFAULT_EXPONENT = 1.0;

        private List<Parameter> parameterList;

        /// Constructor.
        ///
        /// The default exponent is set to noise::module::DEFAULT_EXPONENT.
        public Exponent() : base(1)
        {
            this.exponent = DEFAULT_EXPONENT;
        }

        public override List<Parameter> ParameterList
        {
            get
            {
                if (this.parameterList == null)
                {
                    this.parameterList = new List<Parameter>();
                    this.parameterList.Add(new Parameter("Exponent", "double", DEFAULT_EXPONENT, 0.0, 16.0));
                }

                return this.parameterList;
            }
        }

        /// Returns the exponent value to apply to the output value from the
        /// source module.
        ///
        /// @returns The exponent value.
        ///
        /// Because most noise modules will output values that range from -1.0
        /// to +1.0, this noise module first normalizes this output value (the
        /// range becomes 0.0 to 1.0), maps that value onto an exponential
        /// curve, then rescales that value back to the original range.
        public double GetExponent()
        {
            return this.exponent;
        }

        public override double GetValue(double x, double y, double z, double lowerXBound, double upperXBound, double lowerZBound, double upperZBound)
        {
            System.Diagnostics.Debug.Assert(sourceModule[0] != null, String.Empty);

            return Math.Pow(Math.Abs((sourceModule[0].GetValue(x, y, z, lowerXBound, upperXBound, lowerZBound, upperZBound) + 1.0) * 0.5), this.exponent) * 2.0 - 1.0;
        }

        /// Sets the exponent value to apply to the output value from the
        /// source module.
        ///
        /// @param exponent The exponent value.
        ///
        /// Because most noise modules will output values that range from -1.0
        /// to +1.0, this noise module first normalizes this output value (the
        /// range becomes 0.0 to 1.0), maps that value onto an exponential
        /// curve, then rescales that value back to the original range.
        public void SetExponent(double exponent)
        {
            this.exponent = exponent;
        }

        public override void SetParameter(string name, object value)
        {
            switch (name.ToLower())
            {
                case "exponent":
                    this.SetExponent(Convert.ToDouble(value));
                    break;
            }
        }

        public override object GetParameter(string name)
        {
            switch (name.ToLower())
            {
                case "exponent": return this.GetExponent();
            }

            return null;
        }
    }
}

